<!doctype html>
<html>
    <head>
        <meta charset="UTF-8"/>
        <title>模版管理</title>
	    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
    </head>
    <body>
       <div class="easyui-container-fluid">
          <div class="easyui-panel" style="border: none;">
            <div class="nav" id="nav"></div>
            <div class="easyui-panel" style="border: none;">
                <form id="ff">
                    <div style="margin-bottom: 20px;">
                      <label class="item-label">模版名称：</label>
                      <input type="text" id="name" name="name" class="easyui-textbox" style="width: 100px;"/>
                      <label class="item-label">渠道：</label>
                      <input type="text" id="channel" name="channelCode" class="easyui-combobox" style="width: 100px;"/>
                        <label class="item-label">状态：</label>
                        <input id="entityStatus" class="easyui-switchbutton" checked style="width:80px;height:30px;" onText="启用" offText="禁用"  >

                        <a href="javascript:void(0)" style="margin-left:40px;width: 80px;" class="easyui-linkbutton c8" onclick="searchBy(0,100)">查询</a>
                    </div>
                </form>
            </div>
            <div class="table-wrapper">
             <table id="datagrid" data-options="fitColumns:true,scrollbarSize:0">
               <thead>
                 <tr>
                     <th data-options="field:'code',align:'center'" width="80">代码</th>
                     <th data-options="field:'name',align:'center'" width="100">模版</th>
                     <th data-options="field:'channelCode',align:'center'" width="100">渠道码</th>
                     <th data-options="field:'mallLocation',align:'center'" width="80" formatter=mallLocationFormatter>商场位置</th>
                     <th data-options="field:'categoryLocation',align:'center'" width="80" formatter=categoryLocationFormatter>品类位置</th>
                     <th data-options="field:'operateUser',align:'center'" width="80" formatter="operateUserFormatter">操作人</th>
                     <th data-options="field:'entityStatus',align:'center',formatter:statusFormatter" width="40">状态</th>
                     <th data-options="field:'action',formatter:actions,align:'center'" width="100">操作</th>
                 </tr>
               </thead>
               <tbody>
               </tbody>
             </table>
           </div>
          </div> 
       </div>  
    </body>
    <script type="text/javascript">
           $(function(){
               setNav();
               initChannelSelect("channel");
               var height = $(window).height();
               var nav_height = $("#nav")._outerHeight();
               var ff_height = $("#ff").height();
               var table_height = height-nav_height-ff_height-20;
               $("#datagrid").css("max-height",table_height);
               $("#datagrid").datagrid({
                   pagination:true,
                   rownumbers:true,
                   checkOnSelect:false,
                   toolbar:[{
                        text:"添加模板",
                        handler:function(){
                          window.parent.addTab("添加模版","/webapp/pages/channel/template/add.html");
                        }
                   }],
                   onBeforeSelect:function (index,row) {
                       return false;
                   }

               }).datagrid("getPager").pagination({
                   onSelectPage:searchBy
               });
               searchBy();
               aRecords("模版管理","/webapp/pages/channel/channel/")
           });
           function actions(val,row,index){
               var disableText=row.entityStatus=="OK"?"禁用":"启用";
               var disableStatus=row.entityStatus=="OK"?"DISABLE":"OK";
               return "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' "+
                      "style='width:60px;' onclick='edit(\""+row.id+"\")'>修改</a>&nbsp;&nbsp;"+
                      "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' "+
                      "style='width:60px;' onclick='deleteOne(\""+row.id+"\",\""+disableStatus+"\")'>"+disableText+"</a>&nbsp;&nbsp;"
           }
           function edit(id){
        	   window.parent.addTab("修改模板","/webapp/pages/channel/template/add.html?id="+id);
           }
           function deleteOne(id,status){
              $.ajax({
              	type:"post",
              	url:config.url+"/template/"+id,
              	async:true,
              	data:{"status":status},
              	xhrFields:{withCredentials:true},
              	success:function(data){
              		$.messager.alert("提示","操作成功","info",function () {
                        searchBy();
                    });
              	},
              	error:function(data){
              		$.messager.alert("提示","操作失败","error");
              	}
              });
           }
           function searchBy(page, size){
               var data = getFormData(document.getElementById("ff"));
               data['page'] = !!page?page:1;
               data['size'] = !!size?size:100;
               data.entityStatus = $("#entityStatus").switchbutton("options").checked==true?"OK":"DISABLE";
               $.ajax({
                   url:config.url + "/template/page",
                   type:"get",
                   data:transfer(data),
                   xhrFields:{withCredentials:true},
                   beforeSend:function () {
                       $.messager.progress({
                           title:"请稍等",
                           interval:50,
                           text:"数据加载中..."
                       });
                   },
                   complete:function () {
                       $.messager.progress("close");
                   },
                   success:function(data){
                       $("#datagrid").datagrid("loadData",data);
                       $.messager.progress("close");
                   },
                   error:function(data){
                       console.log(data);
                       $.messager.progress("close");
                   }
               });
           }
           var mallLocationObj = {
           		"FILE":"excel文件名", "SHEET":"sheet名", "COLUMN": "excel列", "NONE":"一个商场"
           }
           var categoryLocationObj = {
           		"FILE":"excel文件名", "SHEET":"sheet名", "COLUMN": "excel列" 
           }
           function mallLocationFormatter(val, row){
           		return !!mallLocationObj[val]?mallLocationObj[val]:val;
           }
           function categoryLocationFormatter(val, row){
           		return !!categoryLocationObj[val]?categoryLocationObj[val]:val;
           }
           function operateUserFormatter(val,row) {
               return val&&val.username||"-";
           }
           $("#ff").keydown(function (event) {
               var e = event || window.event;
               var keyCode = e.keyCode || e.which;
               if(keyCode=="13"){
                   searchBy();
               }
           });
      </script>
</html>
